<!-- 我的申请 -->
<template>
  <div>
    <Form ref="form" @ok="search"></Form>
    <ZgNewPage
      ref="page"
      :uniqueName="uniqueName"
      :pageOpt="pageOpt"
      :dataBtns="dataBtns"
      :adminWidth="200"
      @search="onSearch"
      @filter="onFilter"
      @header="mergeHeader"
      @admin="toAdmin"
    >
      <template slot="columns">
        <a-table-column
          v-for="(h,i) in headers"
          :key="`column${i}`"
          :width="h.width===0 ? 'auto' : h.width"
          align="center"
          :title="h.label">
          <template slot-scope="record">
            {{ record[h.code] }}
          </template>
        </a-table-column>
      </template>
    </ZgNewPage>
  </div>
</template>
<script>
import Form from './Form'
export default {
  components: {
    Form
  },
  data () {
    return {
      uniqueName: 'test',
      pageOpt: {
        showPageTitle: false,
        showConditionBtn: false,
        showHeaderConfig: false,
        showAttachBtn: false
      },
      headers: [
        { code: '1', label: '企业名称', isShow: true, sort: 0, width: 200 },
        { code: '2', label: '企业性质', isShow: true, sort: 0 },
        { code: '3', label: '企业类型', isShow: true, sort: 0 },
        { code: '4', label: '账号姓名', isShow: true, sort: 0 },
        { code: '5', label: '状态', isShow: true, sort: 0 },
        { code: '6', label: '状态说明', isShow: true, sort: 0 },
        { code: '7', label: '申请时间', isShow: true, sort: 0 }
      ],
      dataBtns: [
        { key: 1, name: '查看详情', type: 'link', isShow: () => { return true } },
        { key: 2, name: '编辑', type: 'link', isShow: (row) => ['驳回'].includes(row['5']) }
      ]
    }
  },
  methods: {
    search () {
      const pageRef = this.$refs.page
      if (pageRef) {
        pageRef.search()
      } else {
        setTimeout(() => {
          this.search()
        }, 50)
      }
    },
    onSearch (param) {
      const diyHeaders = localStorage.getItem(this.currentUser.username + '_diyHeader_' + this.uniqueName)
      if (diyHeaders) {
        this.mergeHeader(JSON.parse(diyHeaders))
      }
      // 加载表头
      const list = [
        { key: '1', id: '1', '1': '灵石县玉成煤化有限公司', '2': '外资', '3': '融资企业', '4': '张三', '5': '审核中', '6': '信息完整', '7': '2025-06-19' },
        { key: '2', id: '2', '1': '灵石县玉成煤化有限公司', '2': '外资', '3': '融资企业', '4': '张三', '5': '审核通过', '6': '信息完整', '7': '2025-06-19' },
        { key: '3', id: '4', '1': '灵石县玉成煤化有限公司', '2': '外资', '3': '融资企业', '4': '张三', '5': '驳回', '6': '信息完整', '7': '2025-06-19' }
      ]
      this.$refs.page.endSearch({
        total: list.length,
        list: list
      })
    },
    toAdmin (opt) {
      if (opt.key === 1) {
        this.$refs.form.open('detai', opt.obj)
      } else if (opt.key === 2) {
        this.$refs.form.open('edit', opt.obj)
      }
    },
    onFilter (f, param) {},
    mergeHeader (newHeaders) {
      if (!newHeaders) {
        return
      }
      this.headers = newHeaders.filter(t => {
        return t.isShow
      }).sort((a, b) => {
        return a.sort - b.sort
      })
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
